var grid;
$(document).ready(function() {
    /////////////jehc扩展属性目的可方便使用（boot.js文件datatablesCallBack方法使用） 如弹窗分页查找根据条件 可能此时的form发生变化 此时 可以解决该类问题
    var opt = {
        searchformId:'searchForm'
    };
    var options = DataTablesPaging.pagingOptions({
        ajax:function (data, callback, settings){datatablesCallBack(data, callback, settings,monitorModules+'/graphPel/list',opt);},//渲染数据
        //在第一位置追加序列号
        fnRowCallback:function(nRow, aData, iDisplayIndex){
            jQuery('td:eq(1)', nRow).html(iDisplayIndex +1);
            return nRow;
        },
        order:[],//取消默认排序查询,否则复选框一列会出现小箭头
        tableHeight:datatablesDefaultHeight,
        //列表表头字段
        colums:[
            {
                sClass:"text-center",
                width:"50px",
                data:"graph_pel_id",
                render:function (data, type, full, meta) {
                    return '<label class="mt-checkbox mt-checkbox-single mt-checkbox-outline"><input type="checkbox" name="checkId" class="checkchild " value="' + data + '" /><span></span></label>';
                },
                bSortable:false
            },
            {
                data:"graph_pel_id",
                width:"50px"
            },
            {
                data:'graph_pel_category',
                width:"50px",
                render:function(data, type, row, meta) {
                    if(data=='0'){
                        return '其它';
                    }else if(data=='1'){
                        return '一次接线图';
                    }else if(data=='2'){
                        return '工业';
                    }else if(data=='3'){
                        return '电力';
                    }else{
                        return '缺省';
                    }
                }
            },
            {
                data:'graph_pel_title',
                width:"50px",
            },
            {
                data:'graph_pel_type',
                width:"50px",
                render:function(data, type, row, meta) {
                    if(data=='1'){
                        return '遥测';
                    }else if(data=='2'){
                        return '遥信';
                    }else if(data=='3'){
                        return '遥脉';
                    }else if(data=='4'){
                        return '遥控';
                    }else if(data=='5'){
                        return '虚遥';
                    }else{
                        return '缺省';
                    }
                }
            },
            {
                data:'graph_pel_cell_type',
                width:"50px",
                render:function(data, type, row, meta) {
                    if(data=='0'){
                        return 'svg';
                    }else if(data=='1'){
                        return 'image';
                    }else if(data=='2'){
                        return '其它';
                    }else{
                        return '缺省';
                    }
                }
            },
            {
                data:'graph_pel_status',
                width:"50px",
                render:function(data, type, row, meta) {
                    if(data=='0'){
                        return '未发布';
                    }else if(data=='1'){
                        return '已发布';
                    }else{
                        return '缺省';
                    }
                }
            },
            {
                data:'width',
                width:"50px",
                render:function(data, type, row, meta) {
                    return row.width +"x"+row.height;
                }
            },
            {
                data:"graph_pel_id",
                width:"150px",
                render:function(data, type, row, meta) {
                    var btn = "<a class='m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill' title='详 情' href=\"javascript:toGraphPelDetail('"+ data +"')\"><i class='flaticon-visible'></i></a>";
                    var render_method =  row.render_method;
                    var title = row.graph_pel_title;
                    if(render_method=='1'){
                        btn = btn+'<button onclick=svgEditor("'+data+'","'+title+'") class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill" title="编辑SVG图像"><i class="flaticon-settings-1"></i></button>';
                    }
                    return btn;
                }
            }
        ]
    });
    grid=$('#datatables').dataTable(options);
    //实现全选反选
    docheckboxall('checkall','checkchild');
    //实现单击行选中
    clickrowselected('datatables');
});
//新增
function toGraphPelAdd(){
    tlocation(base_html_redirect+'/monitor/graph-pel/graph-pel-add.html');
}
//修改
function toGraphPelUpdate(){
    if($(".checkchild:checked").length != 1){
        toastrBoot(4,"选择数据非法");
        return;
    }
    var id = $(".checkchild:checked").val();
    tlocation(base_html_redirect+'/monitor/graph-pel/graph-pel-update.html?graph_pel_id='+id);
}
//详情
function toGraphPelDetail(id){
    tlocation(base_html_redirect+'/monitor/graph-pel/graph-pel-detail.html?graph_pel_id='+id);
}

//删除
function delGraphPel(){
    if(returncheckedLength('checkchild') <= 0){
        toastrBoot(4,"请选择要删除的数据");
        return;
    }
    msgTishCallFnBoot("确定要删除所选择的数据？",function(){
        var id = returncheckIds('checkId').join(",");
        var params = {graph_pel_id:id};
        ajaxBReq(monitorModules+'/graphPel/delete',params,['datatables'],null,"DELETE");
    })
}

/**
 * 编辑SVG
 */
function svgEditor(id,title){
    tlocation(base_html_redirect+'/monitor/graph-pel-svgEditor/pelSvgEditor.html?graph_pel_id='+id+'&title='+title);
    // window.top.$('#svnDesignPanelBody').height(reGetBodyHeight()-128);
    // window.top.$('#svnDesignModalLabel').html("图元编辑器---<font color=red>"+title+"</font>");
    // window.top.$('#svnDesignModal').modal({backdrop:'static',keyboard:false});
    // window.top.$('#svnDesignModal').modal({"backdrop":"static"}).modal('show').on("shown.bs.modal",function(){
    //     window.top.$("#svnDesignIframe",document.body).attr("src",base_html_redirect+'/monitor/graph-pel-svgEditor/pelSvgEditor.html?graph_pel_id='+id);
    //     // 是弹出框居中。。。
    //     var $modal_dialog = window.top.$("#svnDesignModalDialog");
    //     $modal_dialog.css({'margin': 0 + 'px auto'});
    //     $modal_dialog.css({'width':reGetBodyWidth()+'px'});
    // });
}

/**
 *
 */
function closeSvnWin() {
    search('datatables');
}